﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Text;
using System.Net;
using System.Net.Sockets;
using System.Threading;
using System.IO;
using System.Windows.Forms;

namespace ComToKey
{
    class DebugInfoSave
    {
        /// <summary>
        /// 保存信息到文件中
        /// </summary>
        /// <param name="str"></param>
        /// <returns></returns>
        public static void Out(string str)
        {
            string cur_dir = Application.StartupPath;
            cur_dir += @"/debuginfo.log";

            FileStream fs = new FileStream(@cur_dir, FileMode.OpenOrCreate, FileAccess.Write);
            StreamWriter m_streamWriter = new StreamWriter(fs);
            m_streamWriter.BaseStream.Seek(0, SeekOrigin.End);//追加到文件尾

            m_streamWriter.WriteLine(str + " " + DateTime.Now.ToString() + "\n");

            m_streamWriter.Flush();
            m_streamWriter.Close();
            fs.Close();
        }

        public static void Out_Debug(string str)
        {
            string cur_dir = Application.StartupPath;
            cur_dir += @"/debug.log";

            FileStream fs = new FileStream(@cur_dir, FileMode.OpenOrCreate, FileAccess.Write);
            StreamWriter m_streamWriter = new StreamWriter(fs);
            m_streamWriter.BaseStream.Seek(0, SeekOrigin.End);//追加到文件尾

            m_streamWriter.WriteLine(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss ") + str + "\n");

            m_streamWriter.Flush();
            m_streamWriter.Close();
            fs.Close();
        }
        public static void NoSleep(string path, byte ch)
        {
            try
            {
                string cur_dir = path;
                cur_dir += @"/nosleep.dat";

                FileStream fs = new FileStream(@cur_dir, FileMode.OpenOrCreate, FileAccess.Write);

                BinaryWriter BinWrite = new BinaryWriter(fs);
                BinWrite.Seek(0, SeekOrigin.End);
                BinWrite.Write(ch);
                BinWrite.Flush();
                BinWrite.Close();
                fs.Close();
            }
            catch (System.Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
            
        }
    }
}
